package config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : example
 * @ Author: XuLeHuang
 * @ Date: 2022/8/10 16:57
 * @ Description:
 */
@Configuration
//@Conditional(value = RedisTemplateCondition.class)
public class RedisTemplateConfig {

    @Autowired
    private LettuceConnectionFactory lettuceConnectionFactory;

    @ConditionalOnMissingBean(
            name = {"redisTemplate"}
    )
    @Bean
    public RedisTemplate<Object, Object> redisTemplate() {
        RedisTemplate<Object, Object> template = new RedisTemplate();
        lettuceConnectionFactory.getPassword();
        lettuceConnectionFactory.setPassword("456");
        template.setConnectionFactory(lettuceConnectionFactory);
        return template;
    }
}
